/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Effects.h"
#include "MudPlayer.h"

#include "MudObjectTask.h"
#include "Global.h"
#include "TaskQueue.h"
#include "config.h"

using namespace Chronos;
using namespace std;

namespace Chronos {

class HealingTask : public MudObjectTask<MudPlayer> {
public:
    HealingTask(MudPlayer& player_, unsigned int hp_, unsigned int interval_, unsigned int times_)
        : MudObjectTask<MudPlayer>(player_)
        , hp(hp_)
        , interval(interval_)
        , times(times_)
    {}
    virtual unsigned int run2() {
        if (object->getHealth() == object->getMaxHealth()) return 0;
        object->heal(hp);
		object->write("Your wounds are closing.\n");
        times--;
        if (times == 0) return 0;
        return interval;
    }
private:
    unsigned int hp;
    unsigned int interval;
    unsigned int times;
};

}


void Chronos::slowHealingEffect(MudPlayer& player) {
	Global<TaskQueue>()->addTask(new HealingTask(player, 10, seconds(5), 5), seconds(1)); 
}


void Chronos::instantHealingEffect(MudPlayer& player) {
    player.heal(100);
}


void Chronos::drunkEffect(MudPlayer& player) {
	player.write("Man..you feel so drunk..\n");
}

